<?php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Form\ContactForm;
use Application\Model\Contact;
use Application;
use Zend\Mvc\Controller\ActionController;
use Zend\Mail;
use Application\Form\SampleForm;


class ContactController extends AbstractActionController
{
    
	public function contactAction(){ 
			date_default_timezone_set('Europe/Paris');
    		$form  = new ContactForm();  	
    		$request = $this->getRequest();
    		if ($request->isPost()) {
    			
    			$sample = new Contact();
    			$form->setInputFilter($sample->getInputFilter());
    			$form->setData($request->getPost());
    		
    			if ($form->isValid()) {
    				
    				$datas = $form->getData() ;
    				
    				$nom  = $datas['nom'];
    				$prenom  = $datas['prenom'];
    				$from  = $datas['email'];
    				
    				$telephone  = $datas['tel'];
    				$objet  = (string)($datas['objet']);
    				$adresse  = $datas['addresse'];
    				$message  = $datas['message'];
    
    				$to = (string)($nom.' '.$prenom);
    				$mail = new Mail\Message();
    				$mail->setBody($message)
    				->setFrom($from,$to)
    				->addTo('lamisa.burundi@gmail.com','LAMISA BURUNDI')
    				->setSubject($objet);

    				$transport = new Mail\Transport\Sendmail();
    				$transport->send($mail);
    			
    		
    				return new ViewModel(array(
    						'services' =>$nom,
    						'form' => $form,
    						'resultat' =>'1',
    				
     				));
    							
    			}else {
    				return array(
    						'form' => $form
    				);
    			}
    		}
    		 
    		return array(
    				'form' => $form
    		);
    	
    }
    
    public function lamisaenimageAction(){
    	return new ViewModel();
    }
 
}
